// 收入渠道分析
function shouRu() {




    $(function() {
        // $.ajax({
        //     url: "http://121.43.103.198:8081/Y/vip", //请求地址
        //     dataType: "json", //数据格式 
        //     type: "get", //请求方式
        //     async: true, //是否异步请求
        //     success: function(res) { //如何发送成功
        //         var html = "";
        //         var data = res.data
        //         console.log(res);

        // console.log(data);
        // for (var i = 0; i < data.length; i++) { //遍历data数组
        //     var bs = data[i];
        //     console.log(bs)
        //     html += `
        //         <li class="clearfix"><span class="pulll_left"><img src="` + bs.picture + `">` + bs.vipid + `-` + bs.name + `</span> <span class="pulll_right">` + bs.age + `岁 - ` + bs.sex + ` - ` + bs.place + ` </span> </li>`
        // }
        var myChart = echarts.init($("#zhanbi02")[0]);
        $.ajax({
            url: "/Y/ru", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功
                console.log(data);
                var html = "";
                html += `    <tr>
                <td>总收入：</td><td colspan="3" class="font01">` + data[0] + `元</td>
            </tr>
            <tr>
                <td>收入渠道数：</td><td colspan="3" class="font03">` + data[1] + `</td>
            </tr>
            <tr><td>收入最多渠道</td><td class="font04">` + data[2].name + `(` + data[2].ratio + `)</td><td>收入最少渠道</td><td class="font05">` + data[3].name + `(` + data[3].ratio + `)</td></tr>`

                var v = data[4];
                console.log(v);
                var vc = new Array();
                for (var i = 0; i < v.length; i++) {
                    console.log(data[4][i].money);
                    vc[i + 1] = data[4][i].money;
                    html +=
                        `  <tr><td>` + data[4][i].name + `收入</td><td class="font6">` + data[4][i].money + `元</td><td>` + data[4][i].name + `收入占比</td><td class="font6">` + data[4][i].ratio + `</td></tr>`
                        // console.log(vc)

                }
                vc[0] = data[0];
                $("#na1").html(html);
                console.log(vc)



                option = {

                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        },
                        formatter: function(params) {
                            var tar = params[0];
                            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
                        }
                    },

                    xAxis: [{
                        type: 'category',
                        splitLine: { show: false },
                        data: ['总收入', '渠道A', '渠道B', '渠道C', '渠道D', '渠道E'],
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                        splitLine: { show: false }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                        splitLine: { show: false }
                    }],
                    series: [{
                            name: '总收入',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    barBorderColor: 'rgba(0,0,0,0)',
                                    color: 'rgba(0,0,0,0)'
                                },
                                emphasis: {
                                    barBorderColor: 'rgba(0,0,0,0)',
                                    color: 'rgba(0,0,0,0)'
                                }
                            },
                            data: [0, 0, 0, 0, 0, 0]
                        },
                        {
                            name: '渠道',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: { normal: { label: { show: true, position: 'inside' } } },
                            data: vc
                        }
                    ]
                };


                myChart.setOption(option);
                window.addEventListener("resize", function() {
                    myChart.resize();
                });
            }
        })
    })

    // 支出渠道分析
    $(function() {
        var myChart = echarts.init($("#zhanbi03")[0]);

        $.ajax({
            url: "/Y/chu", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功
                console.log(data);
                var html = "";
                html += `    <tr>
                <td>总支出：</td><td colspan="3" class="font01">` + data[0] + `元</td>
            </tr>
            <tr>
                <td>支出渠道数：</td><td colspan="3" class="font03">` + data[1] + `</td>
            </tr>
            <tr><td>支出最多渠道</td><td class="font04">` + data[2].name + `(` + data[2].ratio + `)</td><td>支出最少渠道</td><td class="font05">` + data[3].name + `(` + data[3].ratio + `)</td></tr>`

                var v = data[4];
                console.log(v);
                var vc = new Array();
                for (var i = 0; i < v.length; i++) {
                    console.log(data[4][i].money);
                    vc[i + 1] = data[4][i].money;
                    html +=
                        `  <tr><td>` + data[4][i].name + `支出</td><td class="font6">` + data[4][i].money + `元</td><td>` + data[4][i].name + `支出占比</td><td class="font6">` + data[4][i].ratio + `</td></tr>`
                        // console.log(vc)

                }
                vc[0] = data[0];
                $("#na2").html(html);
                console.log(vc)
                option = {

                    tooltip: {
                        trigger: 'axis',
                        axisPointer: { // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
                        },
                        formatter: function(params) {
                            var tar = params[0];
                            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
                        }
                    },

                    xAxis: [{
                        type: 'category',
                        splitLine: { show: false },
                        data: ['总收入', '渠道A', '渠道B', '渠道C', '渠道D', '渠道E'],
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                        splitLine: { show: false }
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                        splitLine: { show: false }
                    }],
                    series: [{
                            name: '总收入',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: {
                                normal: {
                                    lineStyle: {
                                        color: '#b5b5b6'
                                    }
                                }
                            },
                            data: [0, 0, 0, 0, 0, 0]
                        },
                        {
                            name: '渠道',
                            type: 'bar',
                            stack: '总量',
                            itemStyle: { normal: { label: { show: true, position: 'inside' } } },
                            data: vc
                        }
                    ]
                };

                myChart.setOption(option);
                window.addEventListener("resize", function() {
                    myChart.resize();
                });
            }
        })
    })


    $(function() {
        $.ajax({
            url: "/Y/st", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功
                console.log(data);
                console.log(data.profit)

                var ag = '';
                ag += `
<tr>
<td class="font07">销量总量</td>
<td class="font03">` + data.profit + `万元</td>
<td class="font07">营销投入量</td>
<td class="font02">` + data.put + `万</td>
</tr>
<tr>
<td class="font07">总利润</td>
<td class="font01">` + data.sales + `万元</td>
<td class="font07">利润率</td>
<td class="font01">` + data.st + `</td>
</tr> `

                $("#na3").html(ag)
            }
        })

    })

    // 营销投入与销售量分析
    $(function() {
        var myChart = echarts.init($("#allAly01")[0]);


        $.ajax({
            url: "/Y/xiao", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功

                var vc = new Array();
                for (var i = 0; i < data.length; i++) {
                    vc[i] = data[i].name;
                }
                console.log(vc)
                option = {
                    title: {
                        text: '销售量组成',
                        textStyle: {
                            color: "#e9ebee"

                        },

                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        data: vc,
                        textStyle: {
                            color: "#e9ebee"

                        }
                    },

                    calculable: false,
                    series: [{
                        name: '销售组成',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data
                    }]
                };

                myChart.setOption(option);
                window.addEventListener("resize", function() {
                    myChart.resize();
                });
            }
        })
    })





    $(function() {
        var myChart = echarts.init($("#allAly02")[0]);


        $.ajax({
            url: "/Y/tou", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功

                var vc = new Array();
                for (var i = 0; i < data.length; i++) {
                    vc[i] = data[i].name;
                }
                console.log(vc)

                option = {
                    title: {
                        text: '营销投入组成',
                        textStyle: {
                            color: "#e9ebee"

                        },

                        x: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: "{a} <br/>{b} : {c} ({d}%)"
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        data: vc,
                        textStyle: {
                            color: "#e9ebee"

                        }
                    },

                    calculable: false,
                    series: [{
                        name: '销售组成',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '60%'],
                        data: data
                    }]
                };


                myChart.setOption(option);
                window.addEventListener("resize", function() {
                    myChart.resize();
                });
            }
        })
    })




    $(function() {
        var myChart = echarts.init($("#allAly03")[0]);


        $.ajax({
            url: "/Y/month", //请求地址
            dataType: "json", //数据格式 
            type: "get", //请求方式
            async: true, //是否异步请求
            success: function(data) { //如何发送成功

                var vc = new Array();
                var vb = new Array();
                var a = 0;
                for (var i = 0; i < data.length; i++) {
                    vc[i] = data[i].out;
                    vb[i] = data[i].put;
                    if (data[i].out > a)
                        a = data[i].out;
                }
                console.log(a)

                option = {
                    title: {
                        text: '销售量与投入量分析',
                        textStyle: {
                            color: "#e9ebee"

                        },
                        x: 'center'

                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        orient: 'vertical',
                        x: 'left',
                        data: ['营销投入量', '销售量'],
                        textStyle: {
                            color: "#e9ebee"

                        },
                    },

                    calculable: false,
                    xAxis: [{
                        type: 'category',
                        splitLine: { show: false },
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
                    }],
                    yAxis: [{
                        type: 'value',
                        splitLine: { show: false },
                        axisLabel: {
                            formatter: '{value} ',
                            textStyle: {
                                color: '#a4a7ab',
                                align: 'right'
                            }
                        },
                    }],
                    series: [{
                            name: '营销投入量',
                            type: 'bar',
                            data: vb,
                            markPoint: {
                                data: [
                                    { type: 'max', name: '最大值' },
                                    { type: 'min', name: '最小值' }
                                ]
                            },
                            markLine: {
                                data: [
                                    { type: 'average', name: '平均值' }
                                ]
                            }
                        },
                        {
                            name: '销售量',
                            type: 'bar',
                            data: vc,
                            markPoint: {
                                data: [
                                    { type: 'max', name: '最大值' },
                                    { type: 'min', name: '最小值' }
                                ]
                            },
                            markLine: {
                                data: [
                                    { type: 'average', name: '平均值' }
                                ]
                            }
                        }
                    ]
                };



                myChart.setOption(option);
                window.addEventListener("resize", function() {
                    myChart.resize();
                });
            }
        })
    })
}